package com.yiren.dbaa.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yiren.backstage.currency.entity.ProjectEntity;
import com.yiren.dbaa.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by WANGRONGXIANG
 * on 2022/3/29
 * Describe 考试页面灯光弹窗灯光列表适配器
 */
public class ExamLightDialogAdapter extends BaseAdapter {

    private Context context;
    private List<ProjectEntity> lightProjects;

    public ExamLightDialogAdapter(Context context, List<ProjectEntity> lightProjects) {
        this.context = context;
        this.lightProjects = lightProjects;
    }

    @Override
    public int getCount() {
        return lightProjects.size();
    }

    @Override
    public Object getItem(int position) {
        return lightProjects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (null == convertView) {
            convertView = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.item_light_night, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (position == 0) {
            holder.ivLight.setImageResource(R.mipmap.light_random);
        } else {
            holder.ivLight.setImageResource(R.mipmap.light_normal);
        }
        holder.tvLightName.setText(lightProjects.get(position).getName());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.iv_light)
        ImageView ivLight;
        @BindView(R.id.tv_light_name)
        TextView tvLightName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
